package me.zhengjie.modules.utils;


import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.nio.file.*;

@Service
public class FileMover {

    @Value("${file.windows.path}")
    public  String orginFilePath;

    @Value("${backfile.windows.path}")
    public  String DestinateFilePath;


    public  void orginToDesnate(String sourcePath) {
//        String sourcePath = "图片/th-20240402103754339.jpg"; // 源文件路径

        orginFilePath=orginFilePath.substring(0,10);
        // 读取文件
        File sourceFile = new File((orginFilePath + sourcePath));

        // 确保目标路径存在
        File destinationDir = new File(DestinateFilePath);
        if (!destinationDir.exists()) {
            destinationDir.mkdirs();
        }

        System.out.println(sourceFile);
        // 目标文件完整路径
        String destFilePath = DestinateFilePath + sourceFile.getName();

        // 将文件移动到新位置
        try {
            Files.move(sourceFile.toPath(), new File(destFilePath).toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}